package com.dks.controller.publicCompoment;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.dks.dto.BaseIdRequestDto;
import com.dks.dto.publicCompoment.PublicCommentDto;
import com.dks.enumeration.PublicCommentEntityType;
import com.dks.models.publicCompoment.PublicComment;
import com.dks.repository.IPublicCommentRepository;
import com.dks.result.Result;
import com.dks.result.ResultInfo;
import com.dks.result.ResultModel;
import com.dks.util.PageInfo;
import com.dks.vo.publicCompoment.PublicCommentVo;

/**
 * 公共-评论
 */
@RestController
@RequestMapping("comment")
public class PublicCommentController{

    @Autowired
    private IPublicCommentRepository publicCommentRepository;


    /**
     * 新增评论
     * @author evan
     */
    @PostMapping("add")
    public ResultModel<PublicComment> add(@RequestBody @Validated PublicCommentDto publicCommentDto) {
        return publicCommentRepository.add(publicCommentDto);
    }

    /**
     * 删除评论
     * @author evan
     */
    @PostMapping("remove")
    public ResultModel<Boolean> remove(@RequestBody @Validated BaseIdRequestDto baseIdRequestDto) {
        return publicCommentRepository.remove(baseIdRequestDto);
    }

    /**
     * 根据 实体获取 评论
     * @authore evan
     */
    @GetMapping("get/{entityType}/{entityId}")
    public ResultModel<PageInfo<PublicCommentVo>> getListByEntity(@PathVariable("entityType") PublicCommentEntityType publicCommentEntityType,
                                                                  @PathVariable("entityId")Long entityId,
                                                                  @RequestParam(value = "pageNum" ) Integer pageNum,
                                                                  @RequestParam(value = "pageSize") Integer pageSize){
        if(null==pageNum){
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "pageNum");
        }
        if(null==pageSize){
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "pageSize");
        }
        return publicCommentRepository.getListByEntity(publicCommentEntityType, entityId, pageNum, pageSize);
    }

}
